﻿@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.Core.Entity.Domains.Site
@using CoralNode.Core.Entity.Enums
@using CoralNode.Core.Plugin
@using CoralNode.MvcClient.Contexts
@using CoralNode.MvcClient.Helper
@using Coralcode.Utils.Basic
@using System.Linq
@model CoralNode.Core.Entity.Domains.Node.NodeDomain
@{
    ViewData["curr"] = "prototype";
    bool isSeo = false;
    IList<FieldPluginDomain> fieldPlugins = ViewBag.FieldPlugins;
    fieldPlugins = fieldPlugins.Where(n => n.Type == PrototypeEnums.FieldPlugin.Extend).ToList();
}
@Html.IncludePage("CoralAdmin/node", "_Left")
<div id="pbody" class="">
    <div class="extra scrolltab">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">内容管理&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">添加@(Model.Prototype.Title)内容</b></span>
        </div>
        <div id="main">
            <div class="local">
                <a href="/m/node/listNode?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" class="ico ico_back btn">
                </a>
            </div>
            <div class="extra_normal scrolltab-triggers">

                <a href="javascript:">主要信息</a>
                @foreach (PrototypeFieldGroupDomain group in @ViewBag.FieldGroupList) {
                    if (group.FieldList.Count(n => n.FieldType == NodeEnums.FunctionFieldType.Seo) > 0) {
                        isSeo = true;
                    }
                    <a href="javascript:">@group.Title</a>
                }
                @if (isSeo) {
                    <a href="javascript:">SEO设置</a>
                }

            </div>
            <form id="spform" action="/m/node/createpublishedNode?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" method="post">
                @if (@ViewBag.Msg != null) {
                    <div class="error_msg">
                        @ViewBag.Msg.Msg
                    </div>
                }
                <div class="pt_1  scrolltab-items">
                    <div class="table_form form_main " id="主要信息">
                        <div class=" scrolltab-item-t">
                            <span class="btn"></span>主要信息
                        </div>
                        <div class="pl_2">
                            @Html.AntiForgeryToken()
                            @Html.ValidationSummary(true)
                            <table>
                                <tbody>
                                    <tr>
                                        <th width="60"><span class="signmark">*</span>标题：</th>
                                        <td>
                                            @Html.TextBoxFor(m => m.Title, new { @class = "text w_37 required" })
                                            @Html.HiddenFor(n => n.SiteId)
                                            <input type="hidden" name="PrototypeId" value="@Model.PrototypeId"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>所属分类：</th>
                                        <td>
                                            <div class="ztreeContainer">
                                                <input type="text" class="text js_ztree_trigger w_30" value="" id="category_title" />
                                                <input type="hidden" name="CategoryId" id="category_id" value="" />
                                                <span><a id="menuBtn" href="#" class="js_ztree_trigger">选择</a></span>
                                                <ul id="categoryTree" class="ztree" style="margin-top: 0; width: 180px;"></ul>
                                                <textarea class="js_ztree_data">@ViewBag.CategoryList</textarea>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>排序：</th>
                                        <td>@Html.TextBoxFor(m => m.Rank, new { @class = "text w_37" })
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>发布时间：</th>
                                        <td>
                                            <input type="text" class="text w_13 datepicker" name="CreateTime" value="@Model.CreateTime.ToString("yyyy-MM-dd HH:mm")"/>
                                        </td>
                                    </tr>
                                    @if (@ViewBag.ProcessList.Length > 0) {
                                        foreach (var pro in ViewBag.ProcessList) {
                                        <tr>
                                            <th style="width: 80px;">
                                                <label>@pro.Title：</label>
                                            </th>
                                            <td>
                                                <div class="slt js-select" name="process.@(pro.Code)" wd="264" swd="220">
                                                    <div class="curr"><span></span></div>
                                                    <div class="show">
                                                        <ul>
                                                            @foreach (var item in @pro.EntryList) {
                                                                if (pro.DefaultValue == @item.EntryValue) {
                                                                <li  selected="selected" val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                                } else {
                                                                <li  val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                                }
                                                            }
                                                        </ul>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                        }
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                    @foreach (PrototypeFieldGroupDomain group in @ViewBag.FieldGroupList) {
@*<div class="switch_tab">
                            <span class="btn"><i class="ico ico_slideswitch_show"></i></span>@group.Title
                        </div>*@
                        <div class="table_form form_main " id="@group.Title">
                            <div class=" scrolltab-item-t">
                                <span class="btn"></span>@group.Title
                            </div>
                            <div class="pl_2">
                                <table>
                                    <tbody>

                                        @foreach (var item in group.FieldList.Where(n => n.FieldType != NodeEnums.FunctionFieldType.Seo)) {
                                            var fieldPlugin = fieldPlugins.FirstOrDefault(n => n.Id == item.FieldType);
                                            <tr>
                                                <th width="80px">@item.Title：</th>
                                                <td>
                                                    @if (@item.FieldType == NodeEnums.BasicFieldType.TextField) {
                                                        if (string.IsNullOrEmpty(@item.Measurement)) {
                                                        <input class="text w_37" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@item.DefaultValue" />
                                                        } else {
                                                        <input class="text @item.Measurement w_15" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@item.DefaultValue" />
@*<span class="l ml_2">@item.Measurement</span>*@
                                                        }
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.TextArea) {
                                                        <textarea name="field.@item.FieldName" validate="@item.Validator" class="h_8 w_37">@item.DefaultValue</textarea>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.PasswordField) {
                                                        <input name="field.@item.FieldName" class="text w_37" type="password" validate="@item.Validator" value="@item.DefaultValue"/>
                                                        <div class="exp ml_1">@item.Hint</div>
                                       
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.RadioButton) {
                                                        foreach (var e in @item.EntryList) {
                                                            if (@e.EntryValue == @item.DefaultValue) {
                                                        <label class="mr_2">
                                                            <input name="field.@item.FieldName" validate="@item.Validator" class="radio" checked="checked" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                            } else {
                                                        <label class="mr_2">
                                                            <input name="field.@item.FieldName" validate="@item.Validator" class="radio" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                            }
                                                        }
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.CheckBox) {
                                                        foreach (var e in @item.EntryList) {
                                                            if (@ManageHtmlHelper.Contains(@item.DefaultValue, @e.EntryValue)) {
                                                        <label class="mr_2">
                                                            <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox"  checked="checked" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                            } else {
                                                        <label class="mr_2">
                                                            <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                            }
                                                        <div class="exp ml_1">@item.Hint</div>
                                                        }

                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.SelectBox) {
                                                        <select validate="@item.Validator" name="field.@item.FieldName" style="width:382px">
                                                            @foreach (var e in @item.EntryList) {
                                                                if (@e.EntryValue == @item.DefaultValue) {
                                                                <option value="@e.EntryValue" selected="selected">@e.EntryName</option>
                                                                } else {
                                                                <option value="@e.EntryValue">@e.EntryName</option>
                                                                }
                                                            }

                                                        </select>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.FileField) {
                                                        <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'file'}">
                                                                <span class="ico ico_upload_file"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiFile) {
                                                        <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'file'}">
                                                                <span class="ico ico_upload_file"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.ImageField) {
                                                        <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'image'}">
                                                                <span class="ico ico_upload_image"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiImage) {
                                                        <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@item.DefaultValue"/>
                                                        <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                            <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'image'}">
                                                                <span class="ico ico_upload_image"></span>
                                                            </li>
                                                        </ul>
                                                        <div class="exp ml_1">@item.Hint</div>
                                                    } else if (item.FieldType == NodeEnums.BasicFieldType.SingleData) {
                                                        <a class="j_addRelation" num="@item.Measurement" val="@item.DefaultValue" href="/m/node/singlerelation?PrototypeId=@item.DefaultValue">
                                                            请选择@(item.Dataset)</a>
                                                        if (item.Measurement == "1") {
                                                        <input type="hidden" name="field.@item.FieldName" />
                                                        } else {
                                                        <input type="hidden" name="field.@item.FieldName" />
                                                        }

                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.BlockOnTop) {
                                                        foreach (var block in ViewBag.StaticBlockList) {
                                                        <label class="mr_2">
                                                            <input class="checkbox" name="block.TopOn" type="checkbox"  value="@block.Id">
                                                            <span>@block.Title</span>
                                                        </label>
                                                        }
                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.StatVisitInitial) {
                                                        <ul>
                                                            <li>
                                                                <label>初始PV数</label><input class="text w_37" type="text" name="VisitStat.PageView" value="@item.DefaultValue" />
                                                            </li>
                                                            <li>
                                                                <label>初始UV数</label><input class="text w_37" type="text" name="VisitStat.UniqueVisitor" value="@item.DefaultValue" />
                                                            </li>
                                                            <li>
                                                                <label>初始IP数</label><input class="text w_37" type="text" name="VisitStat.IpCount" value="@item.DefaultValue" />
                                                            </li>
                                                        </ul>
                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.Tag) {
                                                        <input type="hidden" id="tag_list" name="tag" />
                                                        <ul class="list_tag">
                                                            <li class="add">
                                                                <span class="tagwrap">
                                                                    <input id="new_tag" class="text w_8 ac_input valid" type="text" autocomplete="off">
                                                                </span>
                                                                <a id="add_tag" class="btn_2 ml_1 btn">添 加</a>
                                                            </li>
                                                        </ul>
                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.Relation) {
                                                        <span>实现中</span>
                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.Comment) {
                                                        <span>无</span>
                                                    } else if (item.FieldType == NodeEnums.FunctionFieldType.Quiz) {
                                                        <span>创建内容后方可管理</span>
                                                    } else if (fieldPlugin != null) {
                                                        @Html.Raw(CoralNodeContext.GetNodeHtml(fieldPlugin.Code, item))
                                                    } else {
                                                        <textarea name="field.@item.FieldName" id="@item.FieldName" ></textarea>
                                                        <script type="text/javascript">
                                                            var edit = UE.getEditor('@item.FieldName');
                                                        </script>
                                                        <div class="exp ml_1">@item.Hint</div> @*
                                                        if (((Dictionary<long, string>)ViewBag.KeywordDict).ContainsKey(item.Id)) {
                                                        <div class="pt_2">
                                                            <span style="float: left;">关键字：</span>
                                                            <input type="text" name="keyword.@item.Id" id="keyword_@item.FieldName" class="text w_30" value="@ViewBag.KeywordDict[item.Id]"  style="margin-right:20px;" />
                                                            <input type="button" value="提取关键字" onclick='@String.Format("getContentTxt(\"{0}\",{1})", item.FieldName, item.Id)' class="btn btn_2 mt_0-5" />
                                                        </div>
                                                        }*@
                                                    }
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    }
                    @if (isSeo) {
                        <div class="table_form form_main" id="SEO设置">
                            <div class=" scrolltab-item-t">
                                <span class="btn"></span>SEO设置
                            </div>
                            <div class="pl_2">
                                <table>
                                    <tbody>
                                        <tr>
                                            <th width="80">页面标题：</th>
                                            <td>
                                                <input type="text" class="text w_37" name="seo.Title" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="60">页面关键字：</th>
                                            <td>
                                                <input type="text" class="text w_37" name="seo.Keyword" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="60">页面描述：</th>
                                            <td>
                                                <textarea name="seo.Description" class="w_58 h_10"></textarea>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    }
                </div>
                <div class="submitbox p_2 extra_normal">
                    <input type="submit" class="btn_1 j_submit" value="立即发布"  data-action="/m/node/createpublishedNode?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" />
                    <input type="submit" class="btn_1 j_submit" value="保存草稿" data-action="/m/node/createdraftnode?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" />
                    <ul style="display: none" id="tag_source">
                        @foreach (var tag in @ViewBag.TagList) {
                            <li>@tag.Title</li>
                        }
                    </ul>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        
        $('.js-copy').click(function () {
            var $this = $(this);

        });
        $('#spform').submit(function (e) {
            $.each($('.coralfile'), function (i, n) {
                var fileArray = new Array();
                $.each($(n).children('.up_file'), function (ii, nn) {
                    fileArray.push($(nn).val());
                    $(n).next("input:hidden").val("[" + fileArray + "]");
                });
            });
            $.each($("#spform input[type='checkbox']"), function (i, n) {
                if ($(n).attr("checked") == "checked") {
                    return false;
                } else {
                    $(n).after('<input type="hidden"  name="' + $(n).attr("name") + '" value="" />');
                    return false;
                }
            });
        });
        $('.j_submit').click(function(e) {
            var $this = $(this).parents('form');
            $this.attr("action", $(this).attr("data-action"));
            e.preventDefault();
            $.post("/m/node/CheckNode", $this.serialize(), function(result) {
                if (result!=null&&result!="") {
                    if (result.Status==3) {
                        $.confirm("检索到回收站里有重复的标题，是否继续", function() {
                            $this.submit();
                        });
                    } else {
                        $.confirm("检索有重复的标题，是否继续", function() {
                            $this.submit();
                        });
                    }
                    
                } else {
                    $this.submit();
                }
            });
        });
    });
    function getContentTxt(fieldName,fieldId) {
        var conent = UE.getEditor(fieldName).getContentTxt();
        $.post(
            '@Url.Action("GetKeyword", "Node")',
            { prototypeId: @Model.PrototypeId, nodeId: @Model.Id, fieldId: fieldId, content: conent },
            function(data) {
                $("#keyword_" + fieldName).val(data);
            }
        );
    }
</script>
